package com.gist.cithub.service.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.gist.cithub.service.entity.ValuateEntity;
import com.gist.cithub.service.service.ValuateService;
import com.gist.common.utils.PageUtils;
import com.gist.common.utils.R;



/**
 * 服务评分
 *
 * @author lejin
 * @email sunlightcs@gmail.com
 * @date 2020-11-23 13:29:16
 */
@RestController
@RequestMapping("service/valuate")
public class ValuateController {
    @Autowired
    private ValuateService valuateService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = valuateService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 或取用户评分
     */
    @RequestMapping("/getUserScore/{serviceId}/{userId}")
    public R getUserScore(@PathVariable("serviceId") Integer serviceId,@PathVariable("userId") Integer userId){
        ValuateEntity valuate = valuateService.getUserScore(serviceId,userId);

        return R.ok().put("score", valuate.getScore());
    }
    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		ValuateEntity valuate = valuateService.getById(id);

        return R.ok().put("valuate", valuate);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody ValuateEntity valuate){
		valuateService.save(valuate);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody ValuateEntity valuate){
		valuateService.updateById(valuate);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		valuateService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
